package com.jinxi.sign.mode.proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Autho changqi.wu
 * @Date 路在脚下，使劲踩！
 */
public class JDKProxy implements InvocationHandler {

    private IService service;

    public Object getInstnce(IService service) {
        this.service = service;
        Class<? extends IService> clazz = service.getClass();
        return Proxy.newProxyInstance(clazz.getClassLoader(),clazz.getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object obj = method.invoke(service, args);
        after();
        return obj;
    }


    public void before() {
        System.out.println("before ");
    }


    public void after() {
        System.out.println("after ");
    }



}
